#pragma once

#include <functional>
class EventLoop;

#include "Channel.h"
#include "InetAddress.h"
#include "Socket.h"

#include "Callbacks.h"

class Acceptor {
public:
    // TEMP:
    static int createNonblocking() {
        int sockfd = ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TCP);
        if (sockfd < 0) {
        }
        return sockfd;
    }

    Acceptor(EventLoop* loop, InetAddress addr);

    void SetConnectionCallback(const NewConnectionCallback& cb);

    // 有新用户连接了
    void HandleRead();

    void Listen();

    int Fd() { return accept_socket_.Fd(); }

    ~Acceptor();

private:
    Socket accept_socket_;  // listenfd_;
    EventLoop* loop_;       // mainloop
    Channel accept_channel_;
    NewConnectionCallback new_connection_callback_;
    bool listening_;
};